﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace WindowsFormsApplication2
{
    class AccesoDatos
    {
        SqlConnection cn;
        SqlCommand cmd;
        //string rutaSQL = "Data Source=localhost;Initial Catalog=MEMOTEST;Integrated Security=True";
        string rutaSQL = @"Data Source=localhost\SQLEXPRESS;Initial Catalog=MEMOTEST;Integrated Security=True";
        public AccesoDatos()
        {
            cn = new SqlConnection(rutaSQL);
        }

        public void abrir()
        {
            cn.Open();
        }

        public void cerrar()
        {
            cn.Close();
        }

        public DataTable obtenerDatos(string consulta)
        {
            DataTable dt = new DataTable();
            this.abrir();
            SqlDataAdapter sdt = new SqlDataAdapter(consulta, cn);
            sdt.Fill(dt);
            return dt;
        }

        public void ejecutarConsulta(string consulta)
        {
            this.abrir();
            cmd = new SqlCommand(consulta,cn);
            cmd.ExecuteNonQuery();
            this.cerrar();
        }

    }
}
